package main

import (
	"warnning-trigger/controller"
	md "warnning-trigger/middleware"
	"warnning-trigger/model"

	"github.com/gin-gonic/gin"
)

func main() {
	dbErr := model.InitMySQLCon()
	if dbErr != nil {
		panic(dbErr)
	}

	model.InitModel()
	defer model.DB.Close()

	router := gin.Default()

	v1 := router.Group("/apis/v1/")
	{
		v1.POST("/register", controller.RegisterUser)
		v1.POST("/login", controller.Login)
	}

	// secure v1
	sv1 := router.Group("/apis/v1/auth/")
	sv1.Use(md.JWTAuth())
	{
		sv1.GET("/time", controller.GetDataByTime)
	}

	router.Run(":8081")
}
